<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page import="coop.bancocredicoop.proyectos.gd.controller.listarArchivos.ListarArchivosController" %>
<%@ page import="coop.bancocredicoop.proyectos.gd.fileListing.DirectoryItem" %>
<%@ page import="java.util.List" %>

<%
	new ListarArchivosController().run(request);
%>


<%@ include file="../header.jsp" %>

    <script type="text/javascript" src="${pageContext.request.contextPath}/js/gd.js"></script>
    <script type="text/javascript">
    function previewDocument(fileName) {
        var baseUrl = '${pageContext.request.contextPath}/documento/abrirArchivo';
        var url = baseUrl + '?fileName=' + fileName;
        var previewer = GD.DocumentPreviewer();
        previewer.previewDocument(url, fileName);
    }
    </script>
    
    <div class="container">
    <div class="main-panel">
    <div class="panel panel-default">
    <c:if test="${currentFolder.isRootDirectory}">
    <div class="panel-heading"><h2>Selecci&oacute;n de archivo <small>Archivos pendientes (<c:out value="${currentFolder.amountOfDocuments}" />)</small></h2></div>
    </c:if>
    <c:if test="${!currentFolder.isRootDirectory}">
    <div class="panel-heading"><h2>Selecci&oacute;n de archivo <small>Archivos pendientes (${currentFolder.relativePath}: <c:out value="${currentFolder.amountOfDocuments}" />)</small></h2></div>
    </c:if>
    <div class="panel-body">
   
   	<!-- BEGIN: flash messages -->
    <c:if test="${!sessionScope.hasErrors && sessionScope.successMessage != null}">
    	<div class="alert alert-success"><c:out value="${sessionScope.successMessage}" /></div> 
    </c:if>
    <c:if test="${sessionScope.hasErrors}">
    	<c:forEach items="${sessionScope.errorMessages}" var="message">
    	<div class="alert alert-danger"><c:out value="${message}" /></div>
    	</c:forEach> 
    </c:if>
    <% 
    	session.setAttribute("hasErrors", null);
    	session.setAttribute("successMessage", null);
    	session.setAttribute("errorMessages", null);
    %>
    <!-- END: flash messages -->

    <table class="table table-hover">
        <thead>
            <tr>
              <th>Archivo</th>
              <th style="text-align: center;">Vista previa</th>
              <th style="text-align: center;">Seleccionar</th>
            </tr>
        </thead>
        <tbody>
        <c:if test="${!currentFolder.isRootDirectory}">
        <tr>
        <td><a href="${pageContext.request.contextPath}/documento/alta?directory=${currentFolder.parentDirectory}">...</a></td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        </tr>
        </c:if>
        <c:forEach items="${listFile}" var="file">
            <tr>
                <c:if test="${!file.isDirectory}">
                <td><c:out value="${file.name}" /></td>
                <td style="text-align: center;"><button type="button" class="btn btn-default" onclick="previewDocument('<c:out value="${file.relativePath}"/>')"><span class="glyphicon glyphicon-eye-open"></span></button></td>
                <td style="text-align: center;"><a role="button" class="btn btn-default" href="${pageContext.request.contextPath}/documento/alta?fileName=${file.relativePath}"><span class="glyphicon glyphicon-step-forward"></span></a></td>
                </c:if>
                <c:if test="${file.isDirectory}">
                <td><a href="${pageContext.request.contextPath}/documento/alta?directory=${file.relativePath}"><span class="glyphicon glyphicon-folder-close"></span>&nbsp;<c:out value="${file.name} (${file.amountOfDocuments})" /></a></td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                </c:if>
            </tr>
        </c:forEach>
        </tbody>
    </table>

    </div>
    </div>
    </div>
    </div>

<%@ include file="../footer.jsp" %>

